#include "analyzer_common.h"

#include <map>
using namespace std;

extern "C"{
    int analyze_block_struct_worker(sparse_matrix_t* s, int block_size){
        sparse_index_t block_length = (s->m + block_size - 1) / block_size;
        map<unsigned long long, int> nnz_counter;
        for(sparse_index_t row = 0; row < s->m; row++){
            for(sparse_pointer_t idx = s->rowpointer[row]; idx < s->rowpointer[row+1]; idx++){
                sparse_index_t col = s->columnindex[idx];
                nnz_counter[(row / block_size) * block_length + (col / block_size)]++;
            }
        }
        double block_sparsity = (((double)(s->nnz)) / (nnz_counter.size() * block_size * block_size));
        printf("block_size = %d, block_sparsity = %lf\n", block_size, block_sparsity);
    }
}
